package com.dudu.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ValidateUtil {
	/**
	 * 验证是否是手机号
	 * 
	 * @param phone
	 * @return
	 */
	public static boolean isMobilePhone(String phone) {
		if (null == phone || phone.equals("")) {
			return false;
		}
		Pattern p = Pattern.compile("^[1][3,4,5,7,8,9][0-9]{9}$");
		Matcher m = p.matcher(phone);
		return m.matches();
	}

	/**
	 * ip 验证
	 * 
	 * @param ipAddress
	 * @return
	 */
	public static boolean isIpv4(String ipAddress) {
		if (null == ipAddress || ipAddress.equals("")) {
			return false;
		}
		String ip = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
				+ "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
				+ "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
				+ "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";

		Pattern pattern = Pattern.compile(ip);
		Matcher matcher = pattern.matcher(ipAddress);
		return matcher.matches();

	}

	/**
	 * 检测邮箱地址是否合法
	 * 
	 * @param email
	 * @return true合法 false不合法
	 */
	public boolean isEmail(String email) {
		if (null == email || "".equals(email))
			return false;
		Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");// 复杂匹配
		Matcher m = p.matcher(email);
		return m.matches();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
